package com.ibeeking.found.open.api.feign.fallback;

import com.ibeeking.found.open.api.common.dto.OrderAddResultDTO;
import com.ibeeking.found.open.api.common.dto.OrderAmountDTO;
import com.ibeeking.found.open.api.common.dto.OrderChargebackDTO;
import com.ibeeking.found.open.api.common.param.ErpPayTypeParam;
import com.ibeeking.found.open.api.common.param.OrderAddParam;
import com.ibeeking.found.open.api.common.param.OrderChargebackParam;
import com.ibeeking.found.open.api.common.query.OrderAmountQuery;
import com.ibeeking.found.open.api.common.query.OrderChargebackQuery;
import com.ibeeking.found.open.api.feign.OrderFeignClient;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class OrderFeignFallbackFactory implements FallbackFactory<OrderFeignClient> {
    @Override
    public OrderFeignClient create(Throwable throwable) {
        return new OrderFeignClient() {

            @Override
            public ResponseResult<OrderAmountDTO> queryAmount(OrderAmountQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询订单金额失败。", null);
            }

            @Override
            public ResponseResult<OrderAddResultDTO> add(OrderAddParam param) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，新增支付成功订单失败。", null);
            }

            @Override
            public ResponseResult<OrderChargebackDTO> queryChargeback(OrderChargebackQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询退货订单失败。", null);
            }

            @Override
            public ResponseResult<Boolean> chargeback(OrderChargebackParam param) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，发起退货申请失败。", false);
            }

            @Override
            public ResponseResult<Boolean> cancelChargeback(OrderChargebackParam param) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，取消退货申请失败。", false);
            }

            @Override
            public ResponseResult<Boolean> successChargeback(OrderChargebackParam param) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，成功退货通知失败。", false);
            }

            @Override
            public ResponseResult<Boolean> savePayType(List<ErpPayTypeParam> params) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，同步支付方式失败。", false);
            }
        };
    }
}
